import AlertUI = layaUI.main.AlertUI;

class Alert extends DialogPanel{
    loadList = ["main"];
    ui : layaUI.main.AlertUI;
    uiClass = layaUI.main.AlertUI;

    constructor() {
        super();
    }

    private static _instance:Alert;//单例
    /**
     * 获取 单例
     */
    public static getInstance():Alert{
        if(Alert._instance == null){
            Alert._instance = new Alert();
        }
        return Alert._instance;
    }

    /**
     * 初始化
     */
    protected onFirst():void{
        this.ui.txtArea.style.align = "center";
        this.ui.txtArea.style.leading = 20;
    }

    public showMsg:string;
    /**
     * 添加到舞台
     */
    protected onShow():void{
        this.ui.txtArea.innerHTML = this.showMsg;
        this.ui.txtArea.y = (this.ui.height - this.ui.txtArea.contextHeight) / 2;

        Laya.timer.loop(5000,this,this.run);
    }

    private run():void{
        this.close();
        Laya.timer.clear(this,this.run);
    }

    /**
     * 从舞台移除
     */
    protected onClose():void{
    }
}